import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import '@/styles/index.scss'
import * as echarts from 'echarts'

createApp(App).use(ElementPlus).use(store).use(router).use(echarts).mount('#app')

router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) { // 需要登录
    if (localStorage.token && localStorage.isLogin === '1') {
      next()
    } else if (to.path !== '/login') {
      // eslint-disable-next-line prefer-const
      let token = localStorage.token
      if (token === 'null' || token === '' || token === undefined) {
        next({ path: '/login' })
      }
    } else {
      next()
    }
  } else {
    next()
  }
})
